package cn.tedu.mybatis;

import org.apache.ibatis.io.Resources;
import org.apache.ibatis.session.SqlSession;
import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

import java.io.IOException;
import java.io.InputStream;
import java.util.List;

public class Testmybatis {
    //测试mybatis
    public static class TestMybatis {
        public static void main(String[] args) throws IOException {
            //加载核心配置文件mybatis-config.xml
            InputStream in = Resources.getResourceAsStream("mybatis-config.xml");
            //创建会话工厂
            SqlSessionFactory factory = new SqlSessionFactoryBuilder().build(in);
            //创建会话
            SqlSession session = factory.openSession();
            //执行SQL
            List<User> list = session.selectList("userMapperNS.getAll");
            //处理返回值
            System.out.println(list);
            for(User u : list){
                System.out.println(u);
            }
        }
    }
}
